home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / php / pear / Net / SmartIRC / irccommands.php < prev    next >
PHP Script  |  2004-03-24  |  13KB  |  432 lines

  1. <?php
  2. /**
  3.  * $Id: irccommands.php,v 1.1 2003/06/10 21:59:28 meebey Exp $
  4.  * $Revision: 1.1 $
  5.  * $Author: meebey $
  6.  * $Date: 2003/06/10 21:59:28 $
  7.  *
  8.  * Copyright (c) 2002-2003 Mirco "MEEBEY" Bauer <mail@meebey.net> <http://www.meebey.net>
  9.  * 
  10.  * Full LGPL License: <http://www.meebey.net/lgpl.txt>
  11.  * 
  12.  * This library is free software; you can redistribute it and/or
  13.  * modify it under the terms of the GNU Lesser General Public
  14.  * License as published by the Free Software Foundation; either
  15.  * version 2.1 of the License, or (at your option) any later version.
  16.  *
  17.  * This library is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20.  * Lesser General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU Lesser General Public
  23.  * License along with this library; if not, write to the Free Software
  24.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  25.  */
  26.  
  27. class Net_SmartIRC_irccommands extends Net_SmartIRC_base
  28. {
  29.     /**
  30.      * sends a new message
  31.      *
  32.      * Sends a message to a channel or user.
  33.      *
  34.      * @see DOCUMENTATION
  35.      * @param integer $type specifies the type, like QUERY/ACTION or CTCP see 'Message Types'
  36.      * @param string $destination can be a user or channel
  37.      * @param string $message the message
  38.      * @return boolean
  39.      * @access public
  40.      */
  41.     function message($type, $destination, $message, $priority = SMARTIRC_MEDIUM)
  42.     {
  43.         switch ($type) {
  44.             case SMARTIRC_TYPE_CHANNEL:
  45.             case SMARTIRC_TYPE_QUERY:
  46.                 $this->_send('PRIVMSG '.$destination.' :'.$message, $priority);
  47.             break;
  48.             case SMARTIRC_TYPE_ACTION:
  49.                 $this->_send('PRIVMSG '.$destination.' :'.chr(1).'ACTION '.$message.chr(1), $priority);
  50.             break;
  51.             case SMARTIRC_TYPE_NOTICE:
  52.                 $this->_send('NOTICE '.$destination.' :'.$message, $priority);
  53.             break;
  54.             case SMARTIRC_TYPE_CTCP: // backwards compatibilty
  55.             case SMARTIRC_TYPE_CTCP_REPLY:
  56.                 $this->_send('NOTICE '.$destination.' :'.chr(1).$message.chr(1), $priority);
  57.             break;
  58.             case SMARTIRC_TYPE_CTCP_REQUEST:
  59.                 $this->_send('PRIVMSG '.$destination.' :'.chr(1).$message.chr(1), $priority);
  60.             break;
  61.             default:
  62.                 return false;
  63.         }
  64.             
  65.         return true;
  66.     }
  67.     
  68.     /**
  69.      * returns an object reference to the specified channel
  70.      *
  71.      * If the channel does not exist (because not joint) false will be returned.
  72.      *
  73.      * @param string $channelname
  74.      * @return object reference to the channel object
  75.      * @access public
  76.      */
  77.     function &channel($channelname)
  78.     {
  79.         if (isset($this->_channels[strtolower($channelname)])) {
  80.             return $this->_channels[strtolower($channelname)];
  81.         } else {
  82.             return false;
  83.         }
  84.     }
  85.     
  86.     // <IRC methods>
  87.     /**
  88.      * Joins one or more IRC channels with an optional key.
  89.      *
  90.      * @param mixed $channelarray
  91.      * @param string $key 
  92.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  93.      * @return void
  94.      * @access public
  95.      */
  96.     function join($channelarray, $key = null, $priority = SMARTIRC_MEDIUM)
  97.     {
  98.         if (!is_array($channelarray)) {
  99.             $channelarray = array($channelarray);
  100.         }
  101.         
  102.         $channellist = implode(',', $channelarray);
  103.         
  104.         if ($key !== null) {
  105.             $this->_send('JOIN '.$channellist.' '.$key, $priority);
  106.         } else {
  107.             $this->_send('JOIN '.$channellist, $priority);
  108.         }
  109.     }
  110.     
  111.     /**
  112.      * parts from one or more IRC channels with an optional reason
  113.      *
  114.      * @param mixed $channelarray 
  115.      * @param string $reason
  116.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  117.      * @return void
  118.      * @access public
  119.      */
  120.     function part($channelarray, $reason = null, $priority = SMARTIRC_MEDIUM)
  121.     {
  122.         if (!is_array($channelarray)) {
  123.             $channelarray = array($channelarray);
  124.         }
  125.         
  126.         $channellist = implode(',', $channelarray);
  127.         
  128.         if ($reason !== null) {
  129.             $this->_send('PART '.$channellist.' :'.$reason, $priority);
  130.         } else {
  131.             $this->_send('PART '.$channellist, $priority);
  132.         }
  133.     }
  134.     
  135.     /**
  136.      * Kicks one or more user from an IRC channel with an optional reason.
  137.      *
  138.      * @param string $channel
  139.      * @param mixed $nicknamearray
  140.      * @param string $reason
  141.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  142.      * @return void
  143.      * @access public
  144.      */
  145.     function kick($channel, $nicknamearray, $reason = null, $priority = SMARTIRC_MEDIUM)
  146.     {
  147.         if (!is_array($nicknamearray)) {
  148.             $nicknamearray = array($nicknamearray);
  149.         }
  150.         
  151.         $nicknamelist = implode(',', $nicknamearray);
  152.         
  153.         if ($reason !== null) {
  154.             $this->_send('KICK '.$channel.' '.$nicknamelist.' :'.$reason, $priority);
  155.         } else {
  156.             $this->_send('KICK '.$channel.' '.$nicknamelist, $priority);
  157.         }
  158.     }
  159.     
  160.     /**
  161.      * gets a list of one ore more channels
  162.      *
  163.      * Requests a full channellist if $channelarray is not given.
  164.      * (use it with care, usualy its a looooong list)
  165.      *
  166.      * @param mixed $channelarray
  167.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  168.      * @return void
  169.      * @access public
  170.      */
  171.     function getList($channelarray = null, $priority = SMARTIRC_MEDIUM)
  172.     {
  173.         if ($channelarray !== null) {
  174.             if (!is_array($channelarray)) {
  175.                 $channelarray = array($channelarray);
  176.             }
  177.             
  178.             $channellist = implode(',', $channelarray);
  179.             $this->_send('LIST '.$channellist, $priority);
  180.         } else {
  181.             $this->_send('LIST', $priority);
  182.         }
  183.     }
  184.  
  185.     /**
  186.      * requests all nicknames of one or more channels
  187.      *
  188.      * The requested nickname list also includes op and voice state
  189.      *
  190.      * @param mixed $channelarray
  191.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  192.      * @return void
  193.      * @access public
  194.      */
  195.     function names($channelarray = null, $priority = SMARTIRC_MEDIUM)
  196.     {
  197.         if ($channelarray !== null) {
  198.             if (!is_array($channelarray)) {
  199.                 $channelarray = array($channelarray);
  200.             }
  201.             
  202.             $channellist = implode(',', $channelarray);
  203.             $this->_send('NAMES '.$channellist, $priority);
  204.         } else {
  205.             $this->_send('NAMES', $priority);
  206.         }
  207.     }
  208.     
  209.     /**
  210.      * sets a new topic of a channel
  211.      *
  212.      * @param string $channel
  213.      * @param string $newtopic
  214.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  215.      * @return void
  216.      * @access public
  217.      */
  218.     function setTopic($channel, $newtopic, $priority = SMARTIRC_MEDIUM)
  219.     {
  220.         $this->_send('TOPIC '.$channel.' :'.$newtopic, $priority);
  221.     }
  222.     
  223.     /**
  224.      * gets the topic of a channel
  225.      *
  226.      * @param string $channel
  227.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  228.      * @return void
  229.      * @access public
  230.      */
  231.     function getTopic($channel, $priority = SMARTIRC_MEDIUM)
  232.     {
  233.         $this->_send('TOPIC '.$channel, $priority);
  234.     }
  235.     
  236.     /**
  237.      * sets or gets the mode of an user or channel
  238.      *
  239.      * Changes/requests the mode of the given target.
  240.      *
  241.      * @param string $target the target, can be an user (only yourself) or a channel
  242.      * @param string $newmode the new mode like +mt
  243.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  244.      * @return void
  245.      * @access public
  246.      */
  247.     function mode($target, $newmode = null, $priority = SMARTIRC_MEDIUM)
  248.     {
  249.         if ($newmode !== null) {
  250.             $this->_send('MODE '.$target.' '.$newmode, $priority);
  251.         } else {
  252.             $this->_send('MODE '.$target, $priority);
  253.         }
  254.     }
  255.     
  256.     /**
  257.      * ops an user in the given channel
  258.      *
  259.      * @param string $channel
  260.      * @param string $nickname
  261.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  262.      * @return void
  263.      * @access public
  264.      */
  265.     function op($channel, $nickname, $priority = SMARTIRC_MEDIUM)
  266.     {
  267.         $this->mode($channel, '+o '.$nickname, $priority);
  268.     }
  269.     
  270.     /**
  271.      * deops an user in the given channel
  272.      *
  273.      * @param string $channel
  274.      * @param string $nickname
  275.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  276.      * @return void
  277.      * @access public
  278.      */
  279.     function deop($channel, $nickname, $priority = SMARTIRC_MEDIUM)
  280.     {
  281.         $this->mode($channel, '-o '.$nickname, $priority);
  282.     }
  283.     
  284.     /**
  285.      * voice a user in the given channel
  286.      *
  287.      * @param string $channel
  288.      * @param string $nickname
  289.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  290.      * @return void
  291.      * @access public
  292.      */
  293.     function voice($channel, $nickname, $priority = SMARTIRC_MEDIUM)
  294.     {
  295.         $this->mode($channel, '+v '.$nickname, $priority);
  296.     }
  297.     
  298.     /**
  299.      * devoice a user in the given channel
  300.      *
  301.      * @param string $channel
  302.      * @param string $nickname
  303.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  304.      * @return void
  305.      * @access public
  306.      */
  307.     function devoice($channel, $nickname, $priority = SMARTIRC_MEDIUM)
  308.     {
  309.         $this->mode($channel, '-v '.$nickname, $priority);
  310.     }
  311.     
  312.     /**
  313.      * bans a hostmask for the given channel or requests the current banlist
  314.      *
  315.      * The banlist will be requested if no hostmask is specified
  316.      *
  317.      * @param string $channel
  318.      * @param string $hostmask
  319.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  320.      * @return void
  321.      * @access public
  322.      */
  323.     function ban($channel, $hostmask = null, $priority = SMARTIRC_MEDIUM)
  324.     {
  325.         if ($hostmask !== null) {
  326.             $this->mode($channel, '+b '.$hostmask, $priority);
  327.         } else {
  328.             $this->mode($channel, 'b', $priority);
  329.         }
  330.     }
  331.     
  332.     /**
  333.      * unbans a hostmask on the given channel
  334.      *
  335.      * @param string $channel
  336.      * @param string $hostmask
  337.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  338.      * @return void
  339.      * @access public
  340.      */
  341.     function unban($channel, $hostmask, $priority = SMARTIRC_MEDIUM)
  342.     {
  343.         $this->mode($channel, '-b '.$hostmask, $priority);
  344.     }
  345.     
  346.     /**
  347.      * invites a user to the specified channel
  348.      *
  349.      * @param string $nickname
  350.      * @param string $channel
  351.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  352.      * @return void
  353.      * @access public
  354.      */
  355.     function invite($nickname, $channel, $priority = SMARTIRC_MEDIUM)
  356.     {
  357.         $this->_send('INVITE '.$nickname.' '.$channel, $priority);
  358.     }
  359.     
  360.     /**
  361.      * changes the own nickname
  362.      *
  363.      * Trys to set a new nickname, nickcollisions are handled.
  364.      *
  365.      * @param string $newnick
  366.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  367.      * @return void
  368.      * @access public
  369.      */
  370.     function changeNick($newnick, $priority = SMARTIRC_MEDIUM)
  371.     {
  372.         $this->_send('NICK '.$newnick, $priority);
  373.     }
  374.     
  375.     /**
  376.      * requests a 'WHO' from the specified target
  377.      *
  378.      * @param string $target
  379.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  380.      * @return void
  381.      * @access public
  382.      */
  383.     function who($target, $priority = SMARTIRC_MEDIUM)
  384.     {
  385.         $this->_send('WHO '.$target, $priority);
  386.     }
  387.     
  388.     /**
  389.      * requests a 'WHOIS' from the specified target
  390.      *
  391.      * @param string $target
  392.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  393.      * @return void
  394.      * @access public
  395.      */
  396.     function whois($target, $priority = SMARTIRC_MEDIUM)
  397.     {
  398.         $this->_send('WHOIS '.$target, $priority);
  399.     }
  400.     
  401.     /**
  402.      * requests a 'WHOWAS' from the specified target
  403.      * (if he left the IRC network)
  404.      *
  405.      * @param string $target
  406.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  407.      * @return void
  408.      * @access public
  409.      */
  410.     function whowas($target, $priority = SMARTIRC_MEDIUM)
  411.     {
  412.         $this->_send('WHOWAS '.$target, $priority);
  413.     }
  414.     
  415.     /**
  416.      * sends QUIT to IRC server and disconnects
  417.      *
  418.      * @param string $quitmessage optional quitmessage
  419.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  420.      * @return void
  421.      * @access public
  422.      */
  423.     function quit($quitmessage = null, $priority = SMARTIRC_MEDIUM)
  424.     {
  425.         if ($quitmessage !== null) {
  426.             $this->_send('QUIT :'.$quitmessage, $priority);
  427.         } else {
  428.             $this->_send('QUIT', $priority);
  429.         }
  430.     }
  431. }
  432. ?>